In the previous videos, we created ranges using, for example, the code:

range(5)

That created a range object with items 0, 1, 2, 3, and 4.


Such a range always starts from 0, but sometimes you may have the need to create a range that starts from another number. For example, to create a range with items 2, 3, 4, and 5, you can do the following:

range(2, 6)


Likewise, to create a range with items 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, and 21, you would do the following:

range(10, 22)

and so on.


You will notice that the numbers in all the above ranges increase by 1. In other words, the step of those ranges is 1, but you can change the step by adding a third argument to the range class as follows:

range(10, 22, 3)

That range would produce a range with items 10, 13, 16, and 19, so at a step of three. You will need to use the above format very soon in a real-world example. Let's move on.